<?php 

require '../include/library.inc.php';
		
		
		
		$num_rows = mysql_num_rows(query("SELECT c.project_id FROM
											projects AS c,
											project_description AS d
										WHERE
										
											c.project_id = d.project_id
											
											AND
											
											d.lang_id = '".$_SESSION['lang_id']."'
											AND c.published"));
		$limit = 5	;								
		$start = $num_rows - $limit;
		
		if($_REQUEST['start'])$start = $num_rows - ($_REQUEST['start']* $limit);
		
		if($start < 0)
		{ 	$limit = abs($start+$limit);
			 $start = 0;
		}
		
		
		$sql = "SELECT
				c.project_id,
				c.history,
				c.cover,
				c.creation_time,
				d.title,
				d.meta_description,
				d.description
				
			FROM
				projects AS c,
				project_description AS d
			WHERE
			
				c.project_id = d.project_id
				
				AND
				
				d.lang_id = '".$_SESSION['lang_id']."'
				AND c.published
				ORDER BY c.creation_time 
				
				LIMIT ".$start.",".$num_rows."
				
			  ";
			$result = query($sql);
			
			while ($row = mysql_fetch_object($result)) {
				
				$date_name = date('d.m.Y',strtotime($row->creation_time)).' г.';
				$date_id = date('d/m/Y',strtotime($row->creation_time));
				
				if($row->history > 0)
				{
					$date_name = $row->history.' г.';
					$date_id = '10/13/'.$row->history;
				}
				
				if($row->history < 0)
				{
					$date_name = abs($row->history).' г. пр. н.е.';
					$date_id = '10/14/'.abs($row->history);
				}
		?>
        
        <div class="item" data-id="<?=$date_id?>" data-name="<?=$date_name?>" data-description="<?=$row->title?>" 
        data-url="<?=HTML_BASE?>project_images/big/<?=$row->cover?>">
            <div style="background-image:url(<?=HTML_BASE?>project_images/covers/<?=$row->cover?>)" ></div>
			<h2><?=$row->title?></h2>
            <div class="zoom"></div>
		</div>
		<div class="item_open" data-id="<?=$date_id?>">
			<div class="timeline_open_content">
			<h2><?=$row->title?></h2>
            
           <?php 
			
			$sql_gal = "SELECT g.file, d.description FROM project_gallery AS g, project_gallery_description AS d
						WHERE project_id = '".$row->project_id."' AND g.id = d.image_id AND d.lang_id = '".$_SESSION['lang_id']."'";
			
			$result_gal = query($sql_gal);
			
			while ($row_gal = mysql_fetch_object($result_gal)) {
					
			?>
            	<a href="<?=HTML_BASE?>project_images/gallery/<?=$row_gal->file?>"  rel="gallery">
			  		<img src="<?=HTML_BASE?>project_images/gallery/th_<?=$row_gal->file?>" height="75"/>
                </a>
            <?php
			}
			?>
            
			<?=$row->description?>
			</div>
		</div>
        
        <?php }?>



